package com.sw.youvote.client.quizwizard;

import java.util.List;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sw.youvote.client.QuizListGUI;
import com.sw.youvote.shared.objects.CandidatureBean;
import com.sw.youvote.shared.objects.QuizBean;

public class AddCandidatureForm {
	
	private TextBox nameField;
	private TextBox descriptionField;
	private TextBox creatormailField;
	private TextBox imageurlField;
	
	private Grid formGrid;
	private Button candidatureButton;

	private PopupPanel panel;
	private QuizListGUI gui;
	private QuizBean quiz;
	
	
	public AddCandidatureForm(QuizListGUI parentGui) {

		/* formulario */
		nameField = new TextBox();
		descriptionField = new TextBox();
		creatormailField = new TextBox();
		imageurlField = new TextBox();


		formGrid = new Grid(5, 2);
		formGrid.setVisible(false);
		// formGrid.setBorderWidth(1);

		// WIDGET - boton add
		candidatureButton = new Button("Add Candidature");
		// WIDGET - boton update
		

		formGrid.setWidget(0, 0, new Label("Name"));
		formGrid.setWidget(0, 1, nameField);

		formGrid.setWidget(1, 0, new Label("Description"));
		formGrid.setWidget(1, 1, descriptionField);

		formGrid.setWidget(2, 0, new Label("Owner email"));
		formGrid.setWidget(2, 1, creatormailField);

		formGrid.setWidget(3, 0, new Label("Image URL"));
		formGrid.setWidget(3, 1, imageurlField);
	
		formGrid.setWidget(4, 0, candidatureButton);
		

		panel = new PopupPanel();

		panel.setPopupPosition(RootPanel.get().getOffsetWidth() / 2
				- panel.getOffsetWidth() / 2,
				RootPanel.get().getOffsetHeight() / 2);
		panel.setWidget(formGrid);
		gui = parentGui;

	}
	
	public void loadForm(QuizBean quizBean) {
    	this.panel.show();
    	this.quiz = quizBean;
    	this.formGrid.setVisible(true);
        
	}
	
	public Button getCandidatureButton(){
		return candidatureButton;
	}
	
	public void  gui_eventCandidatureButtonClicked() {
		CandidatureBean candidature = new CandidatureBean();
		candidature.setName(this.nameField.getText());
		candidature.setDescription(this.descriptionField.getText());
		candidature.setCreatormail(this.creatormailField.getText());
		candidature.setImageurl(this.imageurlField.getText());
		//candidature.setQuiz(this.quiz);
		gui.getQuizService().addCandidature(this.quiz, candidature);
		panel.hide();
		//gui.getFormularioCreacionArea().getPanel().hide();
		gui.getFormularioCreacionArea().loadForm(this.quiz,2);

	}
	
}

